package com.xinqi.modules.chat.chat.group.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.group.dto.req.ChatGroupAdminCreateDTO;
import com.xinqi.modules.chat.chat.group.dto.req.ChatGroupAdminEditDTO;
import com.xinqi.modules.chat.chat.group.dto.req.ChatGroupAdminQueryDTO;
import com.xinqi.modules.chat.chat.group.dto.rsp.ChatGroupAdminResultDTO;
import com.xinqi.modules.chat.chat.group.service.ChatGroupService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ADMIN -- 群聊
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.chat.chat.group.controller.admin.ChatGroupAdminController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/8/22 9:23
 */
@RestController
@RequestMapping("/admin/chat-group")
@RequiredArgsConstructor
public class ChatGroupAdminController {
    private final ChatGroupService chatGroupService;

    @Operation(summary = "群列表 -- 分页")
    @GetMapping("/page")
    public R<PageInfo<ChatGroupAdminResultDTO>> pageAdmin(ChatGroupAdminQueryDTO query) {
        return R.ok(chatGroupService.pageAdmin(query, query));
    }

    @Operation(summary = "创建群组")
    @PostMapping("/create")
    // @Log(title = ServiceNameConstants.XQ_CHAT + " -- 创建群组", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R<Boolean> createAdmin(@Validated @RequestBody ChatGroupAdminCreateDTO dto) {
        return R.data(chatGroupService.createAdmin(LoginHelper.getXqLoginUser(), dto), MessageUtils.message("chat.group.creat.success"));
    }

    @Operation(summary = "编辑群组")
    @PostMapping("/edit")
    //@Log(title = ServiceNameConstants.XQ_CHAT + " -- 编辑群组", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> editAdmin(@Validated @RequestBody ChatGroupAdminEditDTO dto) {
        return R.data(chatGroupService.editAdmin(LoginHelper.getXqLoginUser(), dto), MessageUtils.message("chat.group.edit.success"));
    }

    @Operation(summary = "解散群")
    @GetMapping("/disband/{groupId}")
    //@Log(title = ServiceNameConstants.XQ_CHAT + " -- 解散群", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R<Boolean> disbandAdmin(@PathVariable("groupId") String groupId) {
        return R.data(chatGroupService.disbandAdmin(LoginHelper.getXqLoginUser(), groupId), MessageUtils.message("chat.group.disband.success"));
    }

    @Operation(summary = "群组详情")
    @GetMapping("/info/{groupId}")
    public R<ChatGroupAdminResultDTO> infoAdmin(@PathVariable("groupId") String groupId) {
        return R.data(chatGroupService.infoAdmin(groupId));
    }

}
